<!DOCTYPE html>
<html lang="en">
<head>
	<include data="head.html">
	<import data="css/summernote.css">
	<title>{$title}</title>
</head>
<body data-menu="posts">
	<div class="container">
		<if data="empty($_GET['action']) || $_GET['action'] == 'search'">
			<ul class="nav nav-tabs" role="tablist" id="post-list-tabs">
				<if data="IS_AUTH">
					<li role="presentation">
						<a href="posts.html?page=1">所有({$postCount['all']})</a>
					</li>
				</if>
				<li role="presentation" data="person">
					<a href="posts.html?user_id={@$_GET['user_id'] ?: me_id()}&tablist=person">{$person}的文章({$postCount['person']})</a>
				</li>
				<if data="!empty($_GET['post_id'])">
					<li role="presentation" class="active">
						<a href="#">当前文章</a>
					</li>
					<elseif data="!empty($_GET['keyword'])">
						<li role="presentation" class="active">
							<a href="#">搜索结果({$postCount['search']})</a>
						</li>
					</elseif>
					<elseif data="get_category()">
						<li role="presentation" data="category" class="active">
							<a href="#">当前目录({$postCount['category']})</a>
						</li>
					</elseif>
				</if>
				<li role="presentation" data="new">
					<a href="posts.html?tablist=new&action=add{$categoryId}">新建</a>
				</li>
			</ul>
			<div class="table-responsive">
				<table class="table table-hover" id="post-list-table">
					<thead>
						<tr>
							<th>#</th>
							<th>标题</th>
							<if data="empty($_GET['user_id'])">
								<th>作者</th>
							</if>
							<th>日期</th>
							<th>
								<if data="empty($_GET['post_id'])">
									<select class="form-control" id="change-category">
										<option value="0">分类目录</option>
										<while data="get_multi_category(array('limit'=>100))">
											<option value="{category_id()}"{category_id() == @$_GET['category_id'] ? ' selected' : ''}>
												{category_alias() ?: category_name()}
											</option>
										</while>
									</select>
									<else>
										分类目录
									</else>
								</if>
							</th>
							<th>评论</th>
						</tr>
					</thead>
					<tbody>
						{!$id = 1}
						<while data="admin_fetch_multi_post($_GET)">
							<tr data-id="{post_id()}">
								<td>{$id++}</td>
								<td>
									<a title="查看" target="_blank" href="{get_post_link()}">{post_title()}</a>
								</td>
								<if data="empty($_GET['user_id'])">
									<td>
										<a title="查看此人的文章" href="posts.html?user_id={post_user('id')}&tablist=person">{post_user('nickname') ?: post_user('nickname')}</a>
									</td>
								</if>
								<td>{date('Y-m-d', post_time())}</td>
								<td data="category-name">{post_category('alias') ?: post_category('name')}</td>
								<td>
									<if data="post_comments()">
										<a title="查看详情" href="comments.html?post_id={post_id()}">{post_comments()}</a>
										<else>
											无
										</else>
									</if>
								</td>
							</tr>
						</while>
					</tbody>
				</table>
			</div>
			<div class="modal fade" id="change-category-modal">
				<div class="modal-dialog modal-sm">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
							<h4 class="modal-title">选择目录</h4>
						</div>
						<div class="modal-body">
							<select class="form-control" id="change-category">
								<option value="0">分类目录</option>
								<while data="get_multi_category(array('limit'=>100))">
									<option value="{category_id()}"{category_id() == @$_GET['category_id'] ? ' selected' : ''}>
										{category_alias() ?: category_name()}
									</option>
								</while>
							</select>
						</div>
						<div class="modal-footer">
							<button type="submit" class="btn btn-success">保存</button>
						</div>
					</div>
				</div>
			</div>
			<else>
				{!get_post($_GET)}
				<form class="form-horizontal" id="post-edit-form" role="form" method="post" action="{site_url()}mod.php?post::{get_post() ? 'update' : 'add'}">
					<button type="submit">提交</button>
					<input type="hidden" name="post_thumbnail" value="{post_thumbnail()}">
					<if data="get_post()">
						<input type="hidden" name="post_id" value="{post_id()}">
					</if>
					<div class="form-group">
						<label for="post_title" class="col-sm-2 control-label">文章标题</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="post_title" name="post_title" placeholder="概括文章的主旨" value="{post_title()}">
						</div>
					</div>
					<div class="form-group">
						<label for="post_link" class="col-sm-2 control-label">固定链接</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="post_link" name="post_link" placeholder="自定义文章的 URL 地址" value="{post_link()}">
						</div>
					</div>
					<div class="form-group">
						<label fo r="category_id" class="col-sm-2 control-label">分类目录</label>
						<div class="col-sm-2">
							<select class="form-control" name="category_id" id="category_id">
								<while data="get_multi_category(array('limit'=>100))">
									<option value="{category_id()}"{(category_id() == post_category('id') || @$_GET['category_id'] == category_id()) ? ' selected' : ''}>
										{category_alias() ?: category_name()}
									</option>
								</while>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label for="post_type" class="col-sm-2 control-label">类型</label>
						<div class="col-sm-2">
							<select class="form-control" name="post_type" id="post_type">
								<foreach data="$postType as $k => $v">
									<option value="{$k}"{post_type() == $k ? ' selected' : ''}>
										{$v}
									</option>
								</foreach>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">是否原创</label>
						<div class="col-sm-2">
							{!$original = (post_original() || $_GET['action'] == 'add')}
							<label class="radio-inline">
								<input type="radio" name="post_original" value="true"{$original ? ' checked' : ''}> 是
							</label>
							<label class="radio-inline" title="如果文章不是原创的，你应在末尾添加引用说明">
								<input type="radio" name="post_original" value="false"{$original == false ? ' checked' : ''}> 否
							</label>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">允许评论</label>
						<div class="col-sm-2">
							{!$commentable = (post_commentable() || $_GET['action'] == 'add')}
							<label class="radio-inline">
								<input type="radio" name="post_commentable" value="true"{$commentable ? ' checked' : ''}> 是
							</label>
							<label class="radio-inline">
								<input type="radio" name="post_commentable" value="false"{$commentable == false ? ' checked' : ''}> 否
							</label>
						</div>
					</div>
					<div class="form-group">
						<label for="post_tags" class="col-sm-2 control-label">标签</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="post_tags" name="post_tags" placeholder="设置文章的关键字" value="{post_tags()}">
						</div>
					</div>
					<div class="form-group">
						<label for="post_content" class="col-sm-2 control-label">内容</label>
						<div class="col-sm-10">
							<textarea class="form-control" name="post_content" id="post_content" rows="10">
								{post_content()}
							</textarea>
							<div id="post-content-div">
								{post_content()}
							</div>
						</div>
					</div>
				</form>
			</else>
		</if>
	</div>
	<script>
		TOTAL = {_post('total') ?: 0};
		PAGES = {_post('pages') ?: 0};
		POST_STATIC_URL = '{config("post.staticURL")}';
	</script>
	<include data="foot.html">
	<import data="js/summernote.min.js">
	<import data="js/summernote-zh-CN.min.js">
	<import data="js/date.js">
</body>
</html>